package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.domain.FamilyMemberElder;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.dto.FamilyMemberElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.DeviceDataListVo;
import com.zzyl.nursing.vo.DevicePropertyStatusVo;
import com.zzyl.nursing.vo.FamilyMemberElderVo;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 老人家属Controller
 *
 * @author Lorine
 * @date 2025-03-03
 */
@Api(tags = "老人家属管理")
@RestController
@RequestMapping("/member/user")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private IFamilyMemberElderService familyMemberElderService;

    /**
     * 小程序登录
     *
     * @param userLoginRequestDto
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto userLoginRequestDto) {
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return success(loginVo);
    }

    /**
     * 绑定家人
     *
     * @param familyMemberElderDto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public R bindingElder(@RequestBody FamilyMemberElderDto familyMemberElderDto) {
        familyMemberElderService.bindingElder(familyMemberElderDto);
        return R.ok();
    }

    /**
     * 查询所有已绑定的家人
     */
    @GetMapping("/my")
    @ApiOperation("查询所有已绑定的家人")
    public R<List<FamilyMemberElder>> getMemberElderList() {
        return R.ok(familyMemberElderService.getMemberElderList());
    }

    /**
     * 分页查询已绑定的家人床位设备信息
     */
    @GetMapping("/list-by-page")
    @ApiOperation("分页查询已绑定的家人床位设备信息")
    public R<List<FamilyMemberElderVo>> listByPage() {
        startPage();
        return R.ok((familyMemberElderService.getMemberElderDetailList()));
    }

    /**
     * 查询健康数据
     */
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询健康数据")
    public R<Map<String, DevicePropertyStatusVo>> queryDevicePropertyStatus(@RequestBody DeviceDto deviceDto) {
        return R.ok(familyMemberElderService.queryDevicePropertyStatus(deviceDto));
    }

    /**
     * 按天统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public R<List<DeviceDataListVo>> queryDeviceDataListByDay(String iotId, String functionId, String startTime, String endTime) {
        return R.ok((familyMemberElderService.queryDeviceDataListByDay(iotId, functionId, startTime, endTime)));
    }

    /**
     * 按周统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public R<List<DeviceDataListVo>> queryDeviceDataListByWeek(String iotId, String functionId, String startTime, String endTime) {
        return R.ok((familyMemberElderService.queryDeviceDataListByWeek(iotId, functionId, startTime, endTime)));
    }
}
